<template>
    <div class="myheader">
        <div>
            <span>ToDoList</span>
            <input type="text" v-model="task" placeholder="添加toDo" @keydown.enter="addTask">
        </div>
    </div>
</template>

<script>
import { ref } from 'vue'
import { useStore } from 'vuex'
export default {
    setup() {
        const task = ref('')
        // 引入vuex的属性和方法
        const store = useStore()

        return {
            task,
            addTask() {
                store.commit('addTasks',  task.value)
                task.value = ''
            }
        }
    }
}
</script>

<style scoped lang="scss">
.myheader {
    width: 100%;
    height: 60px;
    background-color: #333;
    color: #fff;
    div {
        width: 800px;
        height: 100%;
        margin: 0 auto;
        display: flex;
        align-items: center;
        justify-content: space-between;
        span {
            font-size: 24px;
            font-weight: bold;
        }
        input {
            width: 400px;
            border: none;
            outline: none;
            height: 30px;
            background-color: #fff;
            border-radius: 8px;
            padding-left: 15px;
        }
    }
}
</style>